#define _CRT_SECURE_NO_WARNINGS 1
#pragma warning(disable:6031)

#include "BinaryTree.h"

static BTNode* BinaryTreeNodeCreat(const BTDataType value)
{
	BTNode* newnode = (BTNode*)malloc(sizeof(BTNode));
	if (newnode == NULL)
	{
		perror("malloc");
		exit(-1);
	}

	newnode->val = value;
	newnode->left = newnode->right = NULL;
	
	return newnode;
}

//int size = 0;
//int TreeSize(BTNode* root)
//{
//	if (root == NULL)
//		return 0;
//
//	++size;
//	TreeSize(root->left);
//	TreeSize(root->right);
//
//	return size;
//}


//int TreeSize(BTNode* root)
//{
//	if (root == NULL)
//		return 0;
//	static int size = 0;
//	++size;
//	TreeSize(root->left);
//	TreeSize(root->right);
//
//	return size;
//}

void TestLeafNodesize(BTNode* root, int* psize)
{
	if (root == NULL)
	{
		return;
	}
	else if (root->left == NULL && root->right == NULL)
	{
		++(*psize);
	}

	TestLeafNodesize(root->left, psize);
	TestLeafNodesize(root->right, psize);
}

int main()
{
	BTNode* n1 = BinaryTreeNodeCreat(1);
	BTNode* n2 = BinaryTreeNodeCreat(2);
	BTNode* n3 = BinaryTreeNodeCreat(3);
	BTNode* n4 = BinaryTreeNodeCreat(4);
	BTNode* n5 = BinaryTreeNodeCreat(5);
	BTNode* n6 = BinaryTreeNodeCreat(6);
	//BTNode* n7 = BinaryTreeNodeCreat(7);

	n1->left = n2;
	n2->left = n3;
	//n2->right = n7;
	n1->right = n4;
	n4->left = n5;
	n4->right = n6;

	//PreOrder(n1);
	//InOrder(n1);
	//PostOrder(n1);
	//printf("%zu\n", TreeNodeSize(n1));
	//printf("%zu\n", LeafNodesize(n1));
	//printf("%d\n", TreeHeight(n1));
	//printf("%d\n", TreeKLevel(n1, -6));
	//LevelOrder(n1);

	//bool ret = BinaryTreeComplete(n1);
	//if (ret)
	//{
	//	printf("True\n");
	//}
	//else
	//{
	//	printf("False\n");
	//}
	//printf("%d\n", TreeSize(n1));
	//printf("%d\n", TreeSize(n1));
	//printf("%d\n", TreeSize(n1));

	//int size = 0;
	//TestLeafNodesize(n1, &size);
	//printf("%d\n", size);

	//printf("%zu\n", LeafNodesize(n1));
	LevelOrder(n1);
	BinaryTreeDestroy(n1);
	return 0;
}